package net.muchine.test.strophe.core.configuration.loader;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Properties;

import net.muchine.test.strophe.core.configuration.Configuration;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class PropertyLoader implements Loader {
	private final Log log = LogFactory.getLog(this.getClass());
	private String propertyLocation;
	
	public Configuration load() {
		Configuration config = new Configuration();
		
		// load properties
		Properties prop = new Properties();
		
		try {
			prop.load(this.getClass().getClassLoader().getResourceAsStream(this.propertyLocation));
		} catch (FileNotFoundException e) {
			log.error(e);
		} catch (IOException e) {
			log.error(e);
		}
		
		config.setBoshUrl(prop.getProperty("strophe.xmpp.bosh.url"));
		config.setXmppDomain(prop.getProperty("strophe.xmpp.domain"));
		
		return config;	
	}
	
	public String getPropertyLocation() {
		return propertyLocation;
	}
	public Loader setPropertyLocation(String propertyLocation) {
		this.propertyLocation = propertyLocation;
		return this;
	}
	
	public static void main(String[] args) {
		Configuration config = new PropertyLoader().setPropertyLocation("system.properties").load();
		System.out.println(config.getBoshUrl());
	}
}
